﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LucyGrid.Messaging
{
	public class Heartbeat
	{
		/// <summary>
		/// Lucygrid node
		/// </summary>
		public string NodeId;
		/// <summary>
		/// Lucygrid worker. Each node can have several workers
		/// </summary>
		public string WorkerId;
		/// <summary>
		/// Grid endpoint working for
		/// </summary>
		public string GridEndpoint;
		
		public Heartbeat()
		{
		}

		public Heartbeat(string heartbeat)
		{
			var parts = heartbeat.Split('|');
			NodeId = parts[0]; 
			WorkerId = parts[1];
			GridEndpoint = parts[2];
		}

		public Heartbeat(Newtonsoft.Json.Linq.JObject jobject)
		{
			NodeId = jobject["NodeId"].ToString();
			WorkerId = jobject["WorkerId"].ToString();
			GridEndpoint = jobject["GridEndpoint"].ToString();
		}

		public override string ToString()
		{
			return string.Format("{0}|{1}|{2}", NodeId, WorkerId, GridEndpoint);
		}
	}
}
